package com.lbg.drug.service.impl;

import com.lbg.drug.commont.untils.PageUtils;
import com.lbg.drug.dto.DrugPage;
import com.lbg.drug.entity.DrugCategory;
import com.lbg.drug.mapper.DrugCategoryMapper;
import com.lbg.drug.service.DrugCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lbg
 * @since 2022-04-26
 */
@Service
public class  DrugCategoryServiceImpl implements DrugCategoryService {

    @Autowired
    private DrugCategoryMapper drugCategoryMapper;


    @Override
    public PageUtils getDrug(DrugPage drugPage) {

        drugPage.setCurrIndex((drugPage.getPageNo() - 1) * drugPage.getPageSize());
        drugPage.setEndIndex(drugPage.getPageSize());


        PageUtils pageUtils = new PageUtils(drugCategoryMapper.getDrugType(drugPage),drugCategoryMapper.getcount(drugPage));


        return pageUtils;
    }

    @Override
    public String add(DrugCategory drugCategory) {
        drugCategoryMapper.insert(drugCategory);
        return drugCategory.getCategoryId();
    }

    @Override
    public void delete(String id) {
        drugCategoryMapper.deleteById(id);

    }

    @Override
    public void update(DrugCategory drugCategory) {
        drugCategoryMapper.updateById(drugCategory);

    }
}
